package com.eden.manage.config;

import eden.api.common.model.EdenResult;
import eden.api.common.utils.ErrorEnums;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RequiredArgsConstructor
@RestControllerAdvice
public class EdenExceptionHandler {

    @ExceptionHandler({RuntimeException.class})
    public EdenResult<?> handlerRuntimeError(RuntimeException ex){
        log.error("eden error",ex);
        ErrorEnums match = ErrorEnums.match(ex.getMessage());
        if(match == null){
            return EdenResult.fail("网络开了小差,请稍后重试");
        }
        if(match.equals(ErrorEnums.NO_AUTH)){
           return  EdenResult.failLogin(match.getMsg());
        }

        return EdenResult.fail(match.getMsg());
    }


}
